home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 June / MacFormat 25.iso / Shareware City / Developers / OutOfPhase1.1 Source / OutOfPhase Folder / SampleView.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-15  |  22.5 KB  |  759 lines  |  [TEXT/KAHL]

  1. /* SampleView.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "SampleView.h"
  31. #include "Memory.h"
  32. #include "SampleStorageDisplay.h"
  33.  
  34.  
  35. struct SampleViewRec
  36.     {
  37.         SampleStorageDisplayRec*    Storage;
  38.         WinType*                                    ScreenID;
  39.         OrdType                                        XLoc;
  40.         OrdType                                        YLoc;
  41.         OrdType                                        Width;
  42.         OrdType                                        Height;
  43.         double                                        XScale;
  44.         long                                            HorizontalIndex;
  45.         long                                            SelectionStart;
  46.         long                                            SelectionEnd;
  47.     };
  48.  
  49.  
  50. /* create a new sample view that will display the specified storage object. */
  51. SampleViewRec*            NewSampleView(WinType* Screen, OrdType XLoc, OrdType YLoc,
  52.                                             OrdType Width, OrdType Height, SampleStorageDisplayRec* TheRawData)
  53.     {
  54.         SampleViewRec*        View;
  55.  
  56.         View = (SampleViewRec*)AllocPtrCanFail(sizeof(SampleViewRec),"SampleViewRec");
  57.         if (View != NIL)
  58.             {
  59.                 View->Storage = TheRawData;
  60.                 View->ScreenID = Screen;
  61.                 View->XLoc = XLoc;
  62.                 View->YLoc = YLoc;
  63.                 View->Width = Width;
  64.                 View->Height = Height;
  65.                 View->XScale = 1;
  66.                 View->HorizontalIndex = 0;
  67.                 View->SelectionStart = 0;
  68.                 View->SelectionEnd = 0;
  69.             }
  70.         return View;
  71.     }
  72.  
  73.  
  74. /* dispose of the sample view.  the raw data object is also disposed. */
  75. void                                DisposeSampleView(SampleViewRec* View)
  76.     {
  77.         CheckPtrExistence(View);
  78.         DisposeSampleStorageDisplay(View->Storage);
  79.         ReleasePtr((char*)View);
  80.     }
  81.  
  82.  
  83. /* redraw one displayed sample line, at the specified X coordinate */
  84. void                                RedrawSampleViewOneLine(SampleViewRec* View, OrdType XPixel)
  85.     {
  86.         long                            NumSampleFrames;
  87.  
  88.         CheckPtrExistence(View);
  89.         SetClipRect(View->ScreenID,View->XLoc,View->YLoc,View->Width,View->Height);
  90.         NumSampleFrames = GetSampleStorageDisplayNumFrames(View->Storage);
  91.         DrawLine(View->ScreenID,eBlack,View->XLoc + XPixel,View->YLoc,0,0);
  92.         DrawLine(View->ScreenID,eBlack,View->XLoc + XPixel,View->YLoc + View->Height,0,0);
  93.         if (GetSampleStorageDisplayNumChannels(View->Storage) == eSampleStereo)
  94.             {
  95.                 OrdType                LeftStart;
  96.                 OrdType                LeftEnd;
  97.                 OrdType                RightStart;
  98.                 OrdType                RightEnd;
  99.                 long                    Index;
  100.                 Patterns            DotColor;
  101.                 Patterns            BackgroundColor;
  102.  
  103.                 /* stereo sample has two panes */
  104.                 LeftStart = View->YLoc + 1;
  105.                 RightEnd = View->YLoc + View->Height - 1;
  106.                 LeftEnd = View->YLoc + (View->Height / 2 - 1);
  107.                 RightStart = LeftEnd + 1;
  108.                 DrawLine(View->ScreenID,eBlack,View->XLoc + XPixel,LeftEnd,0,0);
  109.                 Index = ((XPixel - 1) * View->XScale) + View->HorizontalIndex;
  110.                 if ((Index >= View->SelectionStart) && (Index < View->SelectionEnd))
  111.                     {
  112.                         DotColor = eWhite;
  113.                         BackgroundColor = eBlack;
  114.                     }
  115.                 else if ((View->SelectionStart == View->SelectionEnd)
  116.                     && (Index == View->SelectionStart))
  117.                     {
  118.                         DotColor = eBlack;
  119.                         BackgroundColor = eMediumGrey;
  120.                     }
  121.                 else
  122.                     {
  123.                         DotColor = eBlack;
  124.                         BackgroundColor = eWhite;
  125.                     }
  126.                 if ((Index >= 0) && (Index < NumSampleFrames))
  127.                     {
  128.                         double                    Value;
  129.                         OrdType                    Position;
  130.  
  131.                         DrawLine(View->ScreenID,BackgroundColor,(XPixel - 1) + View->XLoc + 1,
  132.                             LeftStart,0,LeftEnd - LeftStart - 1);
  133.                         Value = largefixed2double(GetSampleStorageDisplayValue(View->Storage,Index,
  134.                             eLeftChannel));
  135.                         Position = ((1 - Value) / 2) * (LeftEnd - LeftStart - 1);
  136.                         DrawLine(View->ScreenID,DotColor,(XPixel - 1) + View->XLoc + 1,
  137.                             LeftStart + Position,0,0);
  138.                         DrawLine(View->ScreenID,BackgroundColor,(XPixel - 1) + View->XLoc + 1,
  139.                             RightStart,0,RightEnd - RightStart - 1);
  140.                         Value = largefixed2double(GetSampleStorageDisplayValue(View->Storage,Index,
  141.                             eRightChannel));
  142.                         Position = ((1 - Value) / 2) * (RightEnd - RightStart - 1);
  143.                         DrawLine(View->ScreenID,DotColor,(XPixel - 1) + View->XLoc + 1,
  144.                             RightStart + Position,0,0);
  145.                     }
  146.                  else
  147.                     {
  148.                         DrawLine(View->ScreenID,eLightGrey,(XPixel - 1) + View->XLoc + 1,
  149.                             LeftStart,0,LeftEnd - LeftStart - 1);
  150.                         DrawLine(View->ScreenID,eLightGrey,(XPixel - 1) + View->XLoc + 1,
  151.                             RightStart,0,RightEnd - RightStart - 1);
  152.                     }
  153.             }
  154.          else
  155.             {
  156.                 OrdType                Start;
  157.                 OrdType                End;
  158.                 long                    Index;
  159.                 Patterns            DotColor;
  160.                 Patterns            BackgroundColor;
  161.  
  162.                 /* mono sample has one pane */
  163.                 Start = View->YLoc + 1;
  164.                 End = View->YLoc + View->Height - 1;
  165.                 Index = ((XPixel - 1) * View->XScale) + View->HorizontalIndex;
  166.                 if ((Index >= View->SelectionStart) && (Index < View->SelectionEnd))
  167.                     {
  168.                         DotColor = eWhite;
  169.                         BackgroundColor = eBlack;
  170.                     }
  171.                 else if ((View->SelectionStart == View->SelectionEnd)
  172.                     && (Index == View->SelectionStart))
  173.                     {
  174.                         DotColor = eBlack;
  175.                         BackgroundColor = eMediumGrey;
  176.                     }
  177.                 else
  178.                     {
  179.                         DotColor = eBlack;
  180.                         BackgroundColor = eWhite;
  181.                     }
  182.                 if ((Index >= 0) && (Index < NumSampleFrames))
  183.                     {
  184.                         double                    Value;
  185.                         OrdType                    Position;
  186.  
  187.                         DrawLine(View->ScreenID,BackgroundColor,(XPixel - 1) + View->XLoc + 1,
  188.                             Start,0,End - Start - 1);
  189.                         Value = largefixed2double(GetSampleStorageDisplayValue(View->Storage,Index,
  190.                             eMonoChannel));
  191.                         Position = ((1 - Value) / 2) * (End - Start - 1);
  192.                         DrawLine(View->ScreenID,DotColor,(XPixel - 1) + View->XLoc + 1,
  193.                             Start + Position,0,0);
  194.                     }
  195.                  else
  196.                     {
  197.                         DrawLine(View->ScreenID,eLightGrey,(XPixel - 1) + View->XLoc + 1,
  198.                             Start,0,End - Start - 1);
  199.                     }
  200.             }
  201.     }
  202.  
  203.  
  204. /* redraw the entire sample view area */
  205. void                                RedrawSampleView(SampleViewRec* View)
  206.     {
  207.         long                        NumSampleFrames;
  208.  
  209.         CheckPtrExistence(View);
  210.         SetClipRect(View->ScreenID,View->XLoc,View->YLoc,View->Width,View->Height);
  211.         DrawBoxFrame(View->ScreenID,eBlack,View->XLoc,View->YLoc,View->Width,View->Height);
  212.         NumSampleFrames = GetSampleStorageDisplayNumFrames(View->Storage);
  213.         if (GetSampleStorageDisplayNumChannels(View->Storage) == eSampleStereo)
  214.             {
  215.                 OrdType                LeftStart;
  216.                 OrdType                LeftEnd;
  217.                 OrdType                RightStart;
  218.                 OrdType                RightEnd;
  219.                 OrdType                Scan;
  220.  
  221.                 /* stereo sample has two panes */
  222.                 LeftStart = View->YLoc + 1;
  223.                 RightEnd = View->YLoc + View->Height - 1;
  224.                 LeftEnd = View->YLoc + (View->Height / 2 - 1);
  225.                 RightStart = LeftEnd + 1;
  226.                 DrawLine(View->ScreenID,eBlack,View->XLoc,LeftEnd,View->Width,0);
  227.                 for (Scan = 0; Scan < View->Width - 2; Scan += 1)
  228.                     {
  229.                         long                                Index;
  230.                         Patterns                        DotColor;
  231.                         Patterns                        BackgroundColor;
  232.  
  233.                         Index = (Scan * View->XScale) + View->HorizontalIndex;
  234.                         if ((Index >= View->SelectionStart) && (Index < View->SelectionEnd))
  235.                             {
  236.                                 DotColor = eWhite;
  237.                                 BackgroundColor = eBlack;
  238.                             }
  239.                         else if ((View->SelectionStart == View->SelectionEnd)
  240.                             && (Index == View->SelectionStart))
  241.                             {
  242.                                 DotColor = eBlack;
  243.                                 BackgroundColor = eMediumGrey;
  244.                             }
  245.                         else
  246.                             {
  247.                                 DotColor = eBlack;
  248.                                 BackgroundColor = eWhite;
  249.                             }
  250.                         if ((Index >= 0) && (Index < NumSampleFrames))
  251.                             {
  252.                                 double                    Value;
  253.                                 OrdType                    Position;
  254.  
  255.                                 DrawLine(View->ScreenID,BackgroundColor,Scan + View->XLoc + 1,
  256.                                     LeftStart,0,LeftEnd - LeftStart - 1);
  257.                                 Value = largefixed2double(GetSampleStorageDisplayValue(View->Storage,
  258.                                     Index,eLeftChannel));
  259.                                 Position = ((1 - Value) / 2) * (LeftEnd - LeftStart - 1);
  260.                                 DrawLine(View->ScreenID,DotColor,Scan + View->XLoc + 1,
  261.                                     LeftStart + Position,0,0);
  262.                                 DrawLine(View->ScreenID,BackgroundColor,Scan + View->XLoc + 1,
  263.                                     RightStart,0,RightEnd - RightStart - 1);
  264.                                 Value = largefixed2double(GetSampleStorageDisplayValue(View->Storage,
  265.                                     Index,eRightChannel));
  266.                                 Position = ((1 - Value) / 2) * (RightEnd - RightStart - 1);
  267.                                 DrawLine(View->ScreenID,DotColor,Scan + View->XLoc + 1,
  268.                                     RightStart + Position,0,0);
  269.                             }
  270.                          else
  271.                             {
  272.                                 DrawLine(View->ScreenID,eLightGrey,Scan + View->XLoc + 1,LeftStart,
  273.                                     0,LeftEnd - LeftStart - 1);
  274.                                 DrawLine(View->ScreenID,eLightGrey,Scan + View->XLoc + 1,RightStart,
  275.                                     0,RightEnd - RightStart - 1);
  276.                             }
  277.                     }
  278.             }
  279.          else
  280.             {
  281.                 OrdType                Start;
  282.                 OrdType                End;
  283.                 OrdType                Scan;
  284.  
  285.                 /* mono sample has one pane */
  286.                 Start = View->YLoc + 1;
  287.                 End = View->YLoc + View->Height - 1;
  288.                 for (Scan = 0; Scan < View->Width - 2; Scan += 1)
  289.                     {
  290.                         long                                Index;
  291.                         Patterns                        DotColor;
  292.                         Patterns                        BackgroundColor;
  293.  
  294.                         Index = (Scan * View->XScale) + View->HorizontalIndex;
  295.                         if ((Index >= View->SelectionStart) && (Index < View->SelectionEnd))
  296.                             {
  297.                                 DotColor = eWhite;
  298.                                 BackgroundColor = eBlack;
  299.                             }
  300.                         else if ((View->SelectionStart == View->SelectionEnd)
  301.                             && (Index == View->SelectionStart))
  302.                             {
  303.                                 DotColor = eBlack;
  304.                                 BackgroundColor = eMediumGrey;
  305.                             }
  306.                         else
  307.                             {
  308.                                 DotColor = eBlack;
  309.                                 BackgroundColor = eWhite;
  310.                             }
  311.                         if ((Index >= 0) && (Index < NumSampleFrames))
  312.                             {
  313.                                 double                    Value;
  314.                                 OrdType                    Position;
  315.  
  316.                                 DrawLine(View->ScreenID,BackgroundColor,Scan + View->XLoc + 1,
  317.                                     Start,0,End - Start - 1);
  318.                                 Value = largefixed2double(GetSampleStorageDisplayValue(View->Storage,
  319.                                     Index,eMonoChannel));
  320.                                 Position = ((1 - Value) / 2) * (End - Start - 1);
  321.                                 DrawLine(View->ScreenID,DotColor,Scan + View->XLoc + 1,
  322.                                     Start + Position,0,0);
  323.                             }
  324.                          else
  325.                             {
  326.                                 DrawLine(View->ScreenID,eLightGrey,Scan + View->XLoc + 1,
  327.                                     Start,0,End - Start - 1);
  328.                             }
  329.                     }
  330.             }
  331.     }
  332.  
  333.  
  334. /* return the number of bits that the sample storage object has */
  335. NumBitsType                    GetSampleViewNumBits(SampleViewRec* View)
  336.     {
  337.         CheckPtrExistence(View);
  338.         return GetSampleStorageDisplayNumBits(View->Storage);
  339.     }
  340.  
  341.  
  342. /* return the number of channels that the sample has */
  343. NumChannelsType            GetSampleViewNumChannels(SampleViewRec* View)
  344.     {
  345.         CheckPtrExistence(View);
  346.         return GetSampleStorageDisplayNumChannels(View->Storage);
  347.     }
  348.  
  349.  
  350. /* return the number of sample frames in the sample */
  351. long                                GetSampleViewNumFrames(SampleViewRec* View)
  352.     {
  353.         CheckPtrExistence(View);
  354.         return GetSampleStorageDisplayNumFrames(View->Storage);
  355.     }
  356.  
  357.  
  358. /* return one point from the sample array.  for mono samples, WhichChannel must be */
  359. /* eMonoChannel.  for stereo samples, it must either be eRightChannel or eLeftChannel */
  360. largefixedsigned        GetSampleViewValue(SampleViewRec* View, long Index,
  361.                                             ChannelType WhichChannel)
  362.     {
  363.         CheckPtrExistence(View);
  364.         return GetSampleStorageDisplayValue(View->Storage,Index,WhichChannel);
  365.     }
  366.  
  367.  
  368. /* change the number of bits the sample is stored as */
  369. MyBoolean                        SetSampleViewNumBits(SampleViewRec* View,
  370.                                             NumBitsType NewNumBits)
  371.     {
  372.         CheckPtrExistence(View);
  373.         SetSampleStorageDisplayNumBits(View->Storage,NewNumBits);
  374.         RedrawSampleView(View);
  375.         return True;
  376.     }
  377.  
  378.  
  379. /* change the number of channels the sample has */
  380. MyBoolean                        SetSampleViewNumChannels(SampleViewRec* View,
  381.                                             NumChannelsType NewNumChannels)
  382.     {
  383.         MyBoolean                    Result;
  384.  
  385.         CheckPtrExistence(View);
  386.         Result = SetSampleStorageDisplayNumChannels(View->Storage,NewNumChannels);
  387.         RedrawSampleView(View);
  388.         return Result;
  389.     }
  390.  
  391.  
  392. void                                SetSampleViewValue(SampleViewRec* View, long Index,
  393.                                             ChannelType WhichChannel, largefixedsigned NewValue)
  394.     {
  395.         CheckPtrExistence(View);
  396.         SetSampleStorageDisplayValue(View->Storage,Index,WhichChannel,NewValue);
  397.         /* don't redraw! */
  398.     }
  399.  
  400.  
  401. /* insert a zero area into the sample.  returns True if successful. */
  402. MyBoolean                        InsertSampleViewArea(SampleViewRec* View, long Index,
  403.                                             long NumFramesToInsert)
  404.     {
  405.         MyBoolean                    ReturnValue;
  406.  
  407.         CheckPtrExistence(View);
  408.         ReturnValue = InsertSampleStorageDisplayArea(View->Storage,Index,NumFramesToInsert);
  409.         if (ReturnValue)
  410.             {
  411.                 View->SelectionStart = Index;
  412.                 View->SelectionEnd = Index + NumFramesToInsert;
  413.                 RedrawSampleView(View);
  414.             }
  415.         return ReturnValue;
  416.     }
  417.  
  418.  
  419. /* delete an area from the sample.  returns True if successful. */
  420. MyBoolean                        DeleteSampleViewArea(SampleViewRec* View, long Index,
  421.                                             long NumFramesToDelete)
  422.     {
  423.         MyBoolean                    ReturnValue;
  424.  
  425.         CheckPtrExistence(View);
  426.         ReturnValue = DeleteSampleStorageDisplayArea(View->Storage,Index,NumFramesToDelete);
  427.         if (ReturnValue)
  428.             {
  429.                 View->SelectionStart = Index;
  430.                 View->SelectionEnd = Index;
  431.                 RedrawSampleView(View);
  432.             }
  433.         SampleViewValidateSelection(View); /* make sure selection is still valid */
  434.         return ReturnValue;
  435.     }
  436.  
  437.  
  438. /* return the index of the leftmost displayed sample frame */
  439. long                                GetSampleViewXOffset(SampleViewRec* View)
  440.     {
  441.         CheckPtrExistence(View);
  442.         return View->HorizontalIndex;
  443.     }
  444.  
  445.  
  446. void                                SetSampleViewXOffset(SampleViewRec* View, long NewXOffset)
  447.     {
  448.         CheckPtrExistence(View);
  449.         if (NewXOffset > GetSampleViewNumFrames(View) - GetSampleViewNumVisibleFrames(View))
  450.             {
  451.                 NewXOffset = GetSampleViewNumFrames(View) - GetSampleViewNumVisibleFrames(View);
  452.             }
  453.         if (NewXOffset < 0)
  454.             {
  455.                 NewXOffset = 0;
  456.             }
  457.         View->HorizontalIndex = NewXOffset;
  458.         RedrawSampleView(View);
  459.     }
  460.  
  461.  
  462. /* return the scaling factor (zoom in/out).  large numbers are compress more. */
  463. double                            GetSampleViewHorizontalScale(SampleViewRec* View)
  464.     {
  465.         CheckPtrExistence(View);
  466.         return View->XScale;
  467.     }
  468.  
  469.  
  470. void                                SetSampleViewHorizontalScale(SampleViewRec* View,
  471.                                             double NewHorizontalScale)
  472.     {
  473.         double                        ZoomFactor;
  474.         long                            HalfVisibleFrames;
  475.  
  476.         CheckPtrExistence(View);
  477.         if (NewHorizontalScale < MINIMUMHORIZSCALE)
  478.             {
  479.                 NewHorizontalScale = MINIMUMHORIZSCALE;
  480.             }
  481.         /* if we zoom in or out, try to center it */
  482.         /* if we zoom in a factor of 2, then we lose 1/4 off each side, thus */
  483.         /* adjust Xposition by 1/4 of visible frames */
  484.         /* if we zoom in a factor of 4, then we lose 6/8 of image, or 3/8 off each side */
  485.         /* if we zoom by 0.5, we gain on each side. */
  486.         HalfVisibleFrames = GetSampleViewNumVisibleFrames(View) / 2;
  487.         ZoomFactor = View->XScale / NewHorizontalScale; /* >1 = zoom in, <1 = zoom out */
  488.         View->HorizontalIndex += HalfVisibleFrames - (HalfVisibleFrames / ZoomFactor);
  489.         if (View->HorizontalIndex < 0)
  490.             {
  491.                 View->HorizontalIndex = 0;
  492.             }
  493.         View->XScale = NewHorizontalScale;
  494.         RedrawSampleView(View);
  495.     }
  496.  
  497.  
  498. /* extract a section of the sample & return a new sample object containing it. */
  499. SampleStorageDisplayRec*    ExtractSampleViewSection(SampleViewRec* View, long Index,
  500.                                             long NumFramesToExtract)
  501.     {
  502.         CheckPtrExistence(View);
  503.         return ExtractSampleStorageDisplaySection(View->Storage,Index,NumFramesToExtract);
  504.     }
  505.  
  506.  
  507. /* insert a sample into our sample at a specified point.  returns True if successful */
  508. MyBoolean                        InsertSampleViewSection(SampleViewRec* View, long Index,
  509.                                             SampleStorageDisplayRec* DataToInsert)
  510.     {
  511.         MyBoolean                    ReturnValue;
  512.  
  513.         CheckPtrExistence(View);
  514.         ReturnValue = InsertSampleStorageDisplaySection(View->Storage,Index,DataToInsert);
  515.         if (ReturnValue)
  516.             {
  517.                 View->SelectionStart = Index;
  518.                 View->SelectionEnd = Index + GetSampleStorageDisplayNumFrames(DataToInsert);
  519.                 RedrawSampleView(View);
  520.             }
  521.         return ReturnValue;
  522.     }
  523.  
  524.  
  525. /* get the start point of the selection */
  526. long                                GetSampleViewSelectStart(SampleViewRec* View)
  527.     {
  528.         CheckPtrExistence(View);
  529.         return View->SelectionStart;
  530.     }
  531.  
  532.  
  533. /* get the end point of the selection */
  534. long                                GetSampleViewSelectEnd(SampleViewRec* View)
  535.     {
  536.         CheckPtrExistence(View);
  537.         return View->SelectionEnd;
  538.     }
  539.  
  540.  
  541. /* set a selection.  if the selection is invalid, it will be corrected. */
  542. void                                SetSampleViewSelection(SampleViewRec* View, long Start, long End)
  543.     {
  544.         CheckPtrExistence(View);
  545.         View->SelectionStart = Start;
  546.         View->SelectionEnd = End;
  547.         SampleViewValidateSelection(View);
  548.         RedrawSampleView(View);
  549.     }
  550.  
  551.  
  552. /* make sure the selection is correct (i.e. not out of range) */
  553. void                                SampleViewValidateSelection(SampleViewRec* View)
  554.     {
  555.         MyBoolean                    SomethingChanged = False;
  556.  
  557.         CheckPtrExistence(View);
  558.         if (View->SelectionStart < 0)
  559.             {
  560.                 SomethingChanged = True;
  561.                 View->SelectionStart = 0;
  562.             }
  563.         if (View->SelectionEnd > GetSampleStorageDisplayNumFrames(View->Storage))
  564.             {
  565.                 SomethingChanged = True;
  566.                 View->SelectionEnd = GetSampleStorageDisplayNumFrames(View->Storage);
  567.             }
  568.         if (View->SelectionStart > View->SelectionEnd)
  569.             {
  570.                 SomethingChanged = True;
  571.                 View->SelectionStart = View->SelectionEnd;
  572.             }
  573.         if (SomethingChanged)
  574.             {
  575.                 RedrawSampleView(View);
  576.             }
  577.     }
  578.  
  579.  
  580. /* return the left edge of the sample view area */
  581. OrdType                            GetSampleViewXLoc(SampleViewRec* View)
  582.     {
  583.         CheckPtrExistence(View);
  584.         return View->XLoc;
  585.     }
  586.  
  587.  
  588. /* return the top edge of the sample view area */
  589. OrdType                            GetSampleViewYLoc(SampleViewRec* View)
  590.     {
  591.         CheckPtrExistence(View);
  592.         return View->YLoc;
  593.     }
  594.  
  595.  
  596. /* return the width of the sample view area */
  597. OrdType                            GetSampleViewWidth(SampleViewRec* View)
  598.     {
  599.         CheckPtrExistence(View);
  600.         return View->Width;
  601.     }
  602.  
  603.  
  604. /* return the height of the sample view area */
  605. OrdType                            GetSampleViewHeight(SampleViewRec* View)
  606.     {
  607.         CheckPtrExistence(View);
  608.         return View->Height;
  609.     }
  610.  
  611.  
  612. /* move the sample view to a new location */
  613. void                                SetSampleViewLocation(SampleViewRec* View, OrdType XLoc,
  614.                                             OrdType YLoc, OrdType Width, OrdType Height)
  615.     {
  616.         CheckPtrExistence(View);
  617.         View->XLoc = XLoc;
  618.         View->YLoc = YLoc;
  619.         View->Width = Width;
  620.         View->Height = Height;
  621.         RedrawSampleView(View);
  622.     }
  623.  
  624.  
  625. /* return the number of frames that are currently displayed. */
  626. long                                GetSampleViewNumVisibleFrames(SampleViewRec* View)
  627.     {
  628.         CheckPtrExistence(View);
  629.         return (View->Width - 2) * View->XScale - 1;
  630.     }
  631.  
  632.  
  633. /* return True if the data has been modified since the last time it was saved */
  634. MyBoolean                        DoesSampleViewNeedToBeSaved(SampleViewRec* View)
  635.     {
  636.         CheckPtrExistence(View);
  637.         return DoesSampleStorageDisplayNeedToBeSaved(View->Storage);
  638.     }
  639.  
  640.  
  641. /* clear the not-saved flag.  this is called when the file is saved */
  642. void                                SampleViewHasBeenSaved(SampleViewRec* View)
  643.     {
  644.         CheckPtrExistence(View);
  645.         SampleStorageDisplayHasBeenSaved(View->Storage);
  646.     }
  647.  
  648.  
  649. /* make a copy of the data in NewData & store it in the current sample.  NewData is */
  650. /* not disposed. */
  651. MyBoolean                        SampleViewSetContents(SampleViewRec* View,
  652.                                             SampleStorageDisplayRec* NewData)
  653.     {
  654.         MyBoolean                    ReturnValue;
  655.  
  656.         CheckPtrExistence(View);
  657.         ReturnValue = SampleStorageDisplaySetContents(View->Storage,NewData);
  658.         if (ReturnValue)
  659.             {
  660.                 View->SelectionStart = 0;
  661.                 View->SelectionEnd = 0;
  662.                 RedrawSampleView(View);
  663.             }
  664.         return ReturnValue;
  665.     }
  666.  
  667.  
  668. /* returns True if there is a selection or False if there is an insertion point. */
  669. MyBoolean                        SampleViewIsThereValidSelection(SampleViewRec* View)
  670.     {
  671.         CheckPtrExistence(View);
  672.         return View->SelectionStart < View->SelectionEnd;
  673.     }
  674.  
  675.  
  676. /* get a copy of the specified channel as an array of fixedpoint numbers */
  677. largefixedsigned*        SampleViewGetChannelFixed(SampleViewRec* View,
  678.                                             ChannelType WhichChannel)
  679.     {
  680.         CheckPtrExistence(View);
  681.         return SampleStorageDisplayGetChannelFixed(View->Storage,WhichChannel);
  682.     }
  683.  
  684.  
  685. /* store a new array of data into the sample (replacing old contents).  returns */
  686. /* True if successful.  this can only be used for mono samples. */
  687. MyBoolean                        SampleViewPutMonoFixed(SampleViewRec* View, largefixedsigned* Data)
  688.     {
  689.         MyBoolean                    Result;
  690.  
  691.         CheckPtrExistence(View);
  692.         Result = SampleStorageDisplayPutMonoFixed(View->Storage,Data);
  693.         SetSampleViewSelection(View,View->SelectionStart,View->SelectionEnd);
  694.         return Result;
  695.     }
  696.  
  697.  
  698. /* store new arrays of data into the sample (replacing old contents).  returns True */
  699. /* if successful.  this can only be used for stereo samples. */
  700. MyBoolean                        SampleViewPutStereoFixed(SampleViewRec* View, largefixedsigned* Left,
  701.                                             largefixedsigned* Right)
  702.     {
  703.         MyBoolean                    Result;
  704.  
  705.         CheckPtrExistence(View);
  706.         Result = SampleStorageDisplayPutStereoFixed(View->Storage,Left,Right);
  707.         SetSampleViewSelection(View,View->SelectionStart,View->SelectionEnd);
  708.         return Result;
  709.     }
  710.  
  711.  
  712. /* flush undo information. */
  713. void                                SampleViewFlushUndo(SampleViewRec* View)
  714.     {
  715.         CheckPtrExistence(View);
  716.         SampleStorageDisplayFlushUndo(View->Storage);
  717.     }
  718.  
  719.  
  720. /* save the current sample configuration into the undo information. */
  721. MyBoolean                        SampleViewSetupForUndo(SampleViewRec* View)
  722.     {
  723.         MyBoolean                    Result;
  724.  
  725.         CheckPtrExistence(View);
  726.         Result = SampleStorageDisplaySetupForUndo(View->Storage);
  727.         RedrawSampleView(View);
  728.         return Result;
  729.     }
  730.  
  731.  
  732. /* find out if it is possible to restore state to the last SampleViewSetupForUndo() */
  733. MyBoolean                        SampleViewUndoAvailable(SampleViewRec* View)
  734.     {
  735.         CheckPtrExistence(View);
  736.         return SampleStorageDisplayUndoAvailable(View->Storage);
  737.     }
  738.  
  739.  
  740. /* attempt to undo.  returns True if successful.  this call swaps the current sample */
  741. /* state with that saved from the last call to SampleViewSetupForUndo(). */
  742. MyBoolean                        SampleViewUndo(SampleViewRec* View)
  743.     {
  744.         MyBoolean                    Result;
  745.  
  746.         CheckPtrExistence(View);
  747.         Result = SampleStorageDisplayUndo(View->Storage);
  748.         RedrawSampleView(View);
  749.         return Result;
  750.     }
  751.  
  752.  
  753. /* get the actual raw sample data */
  754. largefixedsigned*        SampleViewGetActualRawData(SampleViewRec* View)
  755.     {
  756.         CheckPtrExistence(View);
  757.         return SampleStorageDisplayGetActualData(View->Storage);
  758.     }
  759.